﻿using BattleBotsMattAndSunny.Components.Data;
using BattleBotsMattAndSunny.Components.Guns;
using BattleBotsMattAndSunny.Components.Interfaces;
using BattleBotsMattAndSunny.Components.Radar;
using BattleBotsMattAndSunny.Components.Treads;
using Robocode;

namespace BattleBotsMattAndSunny
{
    public class LunchBot : AdvancedRobot
    {
        public IDataManager Data { get; set; }

        public IRadarManager Radar { get; set; }

        public IGunManager Gun { get; set; }

        public ITreadsManager Treads { get; set; }

        public override bool IsAdjustGunForRobotTurn { get { return false; } }

        public LunchBot()
        {
            Data = new DataManager();
            Radar = new BasicRadar(Data, this);
            Gun = new BasicGunner(Data, this);
            Treads = new BasicTreads(Data, this);
        }

        public override void Run()
        {
            IsAdjustRadarForRobotTurn = false;
            IsAdjustRadarForGunTurn = false;
            while (true)
            {
                Treads.Move();   
                Radar.Move();
                if (DistanceRemaining > 0 || TurnRemaining > 0 || GunTurnRemaining > 0 || RadarTurnRemaining > 0)
                    Execute();
            }
        }

        public override void OnScannedRobot(ScannedRobotEvent e)
        {
            if (e != null)
            {
                Radar.Scan(e);
                Gun.OnScannedRobot(e, 2);
                Treads.OnScannedRobot(e);
            }
            //base.OnScannedRobot(e);
        }

        public override void OnHitByBullet(HitByBulletEvent evnt)
        {
            Treads.OnHitByBullet(evnt);
            //todo add radar response
        }

        public override void OnHitWall(HitWallEvent e)
        {
            Treads.OnHitWall(e);
        }
    }
}